class PapelsController < ApplicationController
  # GET /papel
  # GET /papel.xml
  def index
    @papels = Papel.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @papel }
    end
  end

  # GET /papel/1
  # GET /papel/1.xml
  def show
    @papel = Papel.find(params[:id])
    require 'pp'
    pp buscar_actions

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @papel }
    end
  end

  def cont
    controllers = []
    glob = RAILS_ROOT + '/app/controllers/*_controller.rb'
    Dir.glob(glob).each do |f|
      file = File.basename(f).gsub( /^(.+)_controller.rb/, '\1')
      controllers << file
    end
    controllers
  end

  # GET /papel/new
  # GET /papel/new.xml
  def new
    @papel = Papel.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @papel }
    end
  end

  # GET /papel/1/edit
  def edit
    @papel = Papel.find(params[:id])
  end

  # POST /papel
  # POST /papel.xml
  def create
    @papel = Papel.new(params[:papel])
    respond_to do |format|
      if @papel.save
        flash[:notice] = 'Papel was successfully created.'
        format.html { redirect_to(@papel) }
        format.xml  { render :xml => @papel, :status => :created, :location => @papel }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @papel.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /papel/1
  # PUT /papel/1.xml
  def update
    @papel = Papel.find(params[:id])
    ### passa os valores dos direitos a serem relacionados
    ##@papel.direitos_atribuidos = (params[:papel][:direitos_atribuidos])

    respond_to do |format|
      if @papel.update_attributes(params[:papel])
        flash[:notice] = 'Papel atualizado.'
        format.html { redirect_to(papels_url) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @papel.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /papel/1
  # DELETE /papel/1.xml
  def destroy
    @papel = Papel.find(params[:id])
    @papel.destroy
    respond_to do |format|
      format.html { redirect_to(papels_url) }
      format.xml  { head :ok }
    end
  end
end
